package com.yh.homestay.controller;

import com.yh.homestay.aop.SystemLog;
import com.yh.homestay.common.SysRoleEditResult;
import com.yh.homestay.common.HomeStayResult;
import com.yh.homestay.pojo.SysRole;
import com.yh.homestay.service.SysRoleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @ClassName SysRoleController
 * @Description 角色Controller
 * @Date 2020/1/10 9:43
 */
@RestController
@Api(description = "角色管理")
@RequestMapping(value = "/role")
public class SysRoleController {
    @Autowired
    private SysRoleService sysRoleService;

    /**
     * @param roleName
     * @param page
     * @param limit
     * @Date: 2020/1/13 17:11
     * @Description: 获取角色列表
     * @return: com.yh.homestay.common.HomeStayResult
     */
    @RequestMapping(value = "/list",method = RequestMethod.GET)
    @SystemLog(methods = "角色列表", module = "角色管理")
    @ApiOperation(value = "获取角色列表", notes = "获取角色列表信息或者模糊查询数据")
    public HomeStayResult selectAll(String roleName, Integer page, Integer limit) {
        HomeStayResult homeStayResult = sysRoleService.selectAll(roleName, page, limit);
        return homeStayResult;
    }

    /**
     * @param sysRole
     * @Date: 2020/1/13 17:12
     * @Description: 添加角色
     * @return: com.yh.homestay.common.HomeStayResult
     */
    @RequestMapping(value = "/add",method = RequestMethod.POST)
    @SystemLog(methods = "添加角色", module = "角色管理")
    @ApiOperation(value = "添加角色", notes = "添加角色信息")
    public HomeStayResult addSysRole(SysRole sysRole) {
        int Role = sysRoleService.addSysRole(sysRole);
        if (Role > 0) {
            return HomeStayResult.ok();
        } else {
            return HomeStayResult.build(500, "系统正忙,请稍后添加!");
        }
    }

    /**
     * @param id
     * @Date: 2020/1/13 17:12
     * @Description: 回显角色数据
     * @return: com.yh.homestay.common.SysRoleEditResult
     */
    @RequestMapping(value = "/selectOne/{id}",method = RequestMethod.POST)
    @ApiOperation(value = "回显角色数据", notes = "根据id回显角色数据信息")
    public SysRoleEditResult editSysRole(@PathVariable Integer id) {
        SysRoleEditResult sysRoleEditResult = sysRoleService.selectOne(id);
        return sysRoleEditResult;
    }

    /**
     * @param roleId
     * @param roleName
     * @param roleDesc
     * @Date: 2020/1/13 17:12
     * @Description: 修改角色信息
     * @return: com.yh.homestay.common.HomeStayResult
     */
    @RequestMapping(value = "/update",method = RequestMethod.POST)
    @SystemLog(methods = "修改角色信息", module = "角色管理")
    @ApiOperation(value = "修改角色信息", notes = "修改角色信息")
    public HomeStayResult editSysRole(Integer roleId, String roleName, String roleDesc) {
        HomeStayResult update = sysRoleService.update(roleId, roleName, roleDesc);
        return update;
    }

    /**
     * @param id
     * @Date: 2020/1/13 17:12
     * @Description: 删除角色
     * @return: com.yh.homestay.common.HomeStayResult
     */
    @RequestMapping(value = "/delete/{id}",method = RequestMethod.POST)
    @SystemLog(methods = "删除角色", module = "角色管理")
    @ApiOperation(value = "删除角色", notes = "根据id删除角色")
    public HomeStayResult deleteById(@PathVariable Integer id) {
        HomeStayResult delete = sysRoleService.delete(id);
        return delete;
    }

    /**
     * @param ids
     * @Date: 2020/1/13 17:12
     * @Description: 批量删除角色
     * @return: com.yh.homestay.common.HomeStayResult
     */
    @RequestMapping(value = "/deleteBatch",method = RequestMethod.POST)
    @SystemLog(methods = "删除多个角色", module = "角色管理")
    @ApiOperation(value = "批量删除角色", notes = "根据ids批量删除角色")
    public HomeStayResult delectAll(@RequestParam List<Integer> ids) {
        HomeStayResult actionResult = sysRoleService.delectAll(ids);
        return actionResult;
    }
}
